console.log("back");

function getDateTime() {
	Date.prototype.getDateTime = function() {
		var yyyy = this.getFullYear().toString();
		var MM = (this.getMonth() + 1).toString();
		var dd = this.getDate().toString();
		var HH = this.getHours().toString();
		var mm = this.getMinutes().toString();
		var ss = this.getSeconds().toString();
		var datetime = "日期时间:" + yyyy + "-" + (MM[1] ? MM : "0" + MM[0]) + "-"
				+ (dd[1] ? dd : "0" + dd[0]);
		datetime += " " + (HH[1] ? HH : "0" + HH[0]) + ":"
				+ (mm[1] ? mm : "0" + mm[0]) + ":" + (ss[1] ? ss : "0" + ss[0]);
		// datetime += tab+"当前:" + numberForamt(this.getTime());
		return datetime;
	};
	var date = new Date();
	return date.getDateTime();
}

var msgTotal = {};

function msg(data) {
	var notification;
	// 检测是否具有相关"桌面通知"权限
	if (window.webkitNotifications.checkPermission() == 0) {
		console.info("use notice");
	} else {
		console.info("can't use notice");
		window.webkitNotifications.requestPermission();
	}
	// 桌面通知
	notification = webkitNotifications.createNotification(
			'icons/feedly-48.png', '提醒', data+"\n\r"+getDateTime());
	// 跳转
	notification.onclick = function(event) {
		console.log("onclick");
	}
	// 自动关闭
	notification.ondisplay = function(event) {
		setTimeout(function() {
			event.currentTarget.cancel();
		}, 5000);
	}
	notification.show();
	// 3秒后消失
	// chrome.alarms.create('close', {
	// when : Date.now() + 3000
	// });
}

// chrome.alarms.onAlarm.addListener(function(alarm) {
// console.info("fire onAlarm");
// console.dir(alarm);
// console.dir(window.webkitNotifications);
// // chrome.alarms.clear("close");
// });

// function close(notification) {
// notification.close();
// }

msg("开启");

// console.dir(notification);
// notification.close();

// setTimeout(close(), 5000);
